<?php
/**
 * Brand.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-02-13 22:15:14
 * @modified    2023-02-13 22:15:14
 *
 */

namespace App\Models\Product;

use App\Models\BaseModel;
use App\Services\ImageService;
use Carbon\Carbon;

class Brand extends BaseModel
{
    protected $table = 'product_brand';

    protected $fillable =[
        'name',
        'image',
        'sort_order',
        'status',
        'create_user_id'
    ];

    protected $casts = [
        'id' => 'integer',
        'status' => 'string'
    ];

    protected $appends = [
        'image_url',
        'create_time_format',
        'update_time_format',
    ];

    public function getImageUrlAttribute()
    {
        return (new ImageService($this->image ?? ''))->getUrl();
    }

    public function getCreateTimeFormatAttribute()
    {
        return Carbon::parse($this->create_time)->toDateTimeString();
    }

    public function getUpdateTimeFormatAttribute()
    {
        return Carbon::parse($this->update_time)->toDateTimeString();
    }
}